package jianzhi

import "math"

type MinStack struct {
	stack []int
	min   []int
}

/** initialize your data structure here. */
func Constructor30() MinStack {
	return MinStack{
		stack: []int{},
		min:   []int{math.MaxInt64},
	}
}

func less(i, j int) int {
	if i <= j {
		return i
	} else {
		return j
	}
}

func (this *MinStack) Push(x int) {
	this.stack = append(this.stack, x)
	this.min = append(this.min, less(this.min[len(this.min)-1], x))
}

func (this *MinStack) Pop() {
	// val := this.stack[len(this.stack)-1]
	this.stack = this.stack[:len(this.stack)-1]
	this.min = this.min[:len(this.min)-1]

}

func (this *MinStack) Top() int {
	val := this.stack[len(this.stack)-1]
	return val
}

func (this *MinStack) Min() int {
	return this.min[len(this.min)-1]
}
